package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.hr.dto.EmpContactsAddDTO;
import org.jsola.hr.dto.EmpContactsUpdateDTO;
import org.jsola.hr.entity.EmpContactsDO;
import org.jsola.hr.query.EmpContactsQuery;
import org.jsola.hr.service.IEmpContactsService;
import org.jsola.hr.vo.EmpContactsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 员工联系人
 *
 * @author zhr
 */
@Component
public class EmpContactsTestHelper extends BaseTestHelper {
    
    @Autowired
    private IEmpContactsService empContactsService;

    /**
     * 生成add测试数据
     * @return EmpContactsAddDTO
     */
    public EmpContactsAddDTO getEmpContactsAddDTO(){
        EmpContactsAddDTO empContactsAddDTO = new EmpContactsAddDTO();
        empContactsAddDTO.setEmpId(getRandomValue("varchar",32));
        empContactsAddDTO.setName(getRandomValue("varchar",255));
        empContactsAddDTO.setRelation(getRandomValue("varchar",255));
        empContactsAddDTO.setBirthday((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empContactsAddDTO.setPhone(getRandomValue("varchar",20));
        empContactsAddDTO.setAddress(getRandomValue("varchar",100));
        empContactsAddDTO.setWorkUnit(getRandomValue("varchar",255));
        empContactsAddDTO.setPosition(getRandomValue("varchar",255));
        empContactsAddDTO.setPoliticalStatus(getRandomValue("varchar",50));
        empContactsAddDTO.setCompanyId(getRandomValue("varchar",32));
        return empContactsAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmpContactsUpdateDTO
     */
    public EmpContactsUpdateDTO getEmpContactsUpdateDTO(EmpContactsVO empContactsVO){
        return empContactsService.selectDOById(empContactsVO.getId(), SITE_ID).to(EmpContactsUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmpContactsQuery
     */
    public EmpContactsQuery getEmpContactsQuery() {
        EmpContactsQuery empContactsQuery = new EmpContactsQuery();
        List<EmpContactsDO> empContactsDOList = empContactsService.list(new EmpContactsDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(empContactsDOList)) {
            EmpContactsDO empContactsDO = empContactsDOList.get(0);
            empContactsQuery = empContactsDO.to(EmpContactsQuery.class);
            if (empContactsDO.getGmtCreate() != null) {
                empContactsQuery.setGmtCreateStart(DateKit.getBeforeDay(empContactsDO.getGmtCreate(),-1));
                empContactsQuery.setGmtCreateEnd(DateKit.getBeforeDay(empContactsDO.getGmtCreate(),1));
            }
            if (empContactsDO.getGmtModified() != null) {
                empContactsQuery.setGmtModifiedStart(DateKit.getBeforeDay(empContactsDO.getGmtModified(),-1));
                empContactsQuery.setGmtModifiedEnd(DateKit.getBeforeDay(empContactsDO.getGmtModified(),1));
            }
        }
        return empContactsQuery;
    }

    /**
     * 保存示例
     * @return EmpContactsVO
     */
    public EmpContactsVO saveEmpContactsExample(){
        EmpContactsAddDTO addDTO = this.getEmpContactsAddDTO();
        EmpContactsVO empContactsVO = empContactsService.save(addDTO,buildTokenUser());
        return empContactsVO;
    }


}

